/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logica;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Smuggler
 */
public class correoElectronico {

    private static boolean segundaRevicion(String emailAddress) {
        Pattern pattern = Pattern.compile("^([\\w]((\\.(?!\\.))|[-!#\\$%'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[\\w])@(([\\w][-\\w]*[\\w]\\.)+[a-zA-Z]{2,6})$", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(emailAddress);
        return matcher.matches();
    }

    private static boolean primeraRevicion(String emailAddress) {
       
        Pattern pattern = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(emailAddress);

        if (matcher.matches()) {
            return segundaRevicion(emailAddress);

        }
        return false;

    }
    private static String encontrarUsuario(String cadena) {
        for (int i = 0; i < cadena.length(); i++) {
            if (cadena.charAt(i) == '@') {
                return( cadena.substring(0,i ));
            }
        }
        return cadena;
    }
    
    public static String getencontrarUsuario (String cadena){
       
        return encontrarUsuario(cadena);
    }
    
    
    public static  boolean getcorreoElectronico (String emailAddress){
    
    return primeraRevicion(emailAddress);
    }
}
